package cn.zh.planmanager.domain.plan.service.impl;

import cn.zh.planmanager.domain.plan.convert.PlanConvert;
import cn.zh.planmanager.domain.plan.model.entity.Plan;
import cn.zh.planmanager.domain.plan.model.entity.PlanSet;
import cn.zh.planmanager.domain.plan.service.PlanService;
import cn.zh.planmanager.domain.plan.repository.PlanRepository;
import cn.zh.planmanager.domain.plan.repository.PlanSetRepository;
import cn.zh.planmanager.infrastructure.entity.PlanEntity;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

/**
 * @author zh
 */
@Service
@RequiredArgsConstructor
public class PlanServiceImpl implements PlanService {

    private final PlanRepository planRepository;

    private final PlanSetRepository planSetRepository;

    @Override
    public Plan findPlanById(Long id) {
        PlanEntity planEntity = planRepository.findById(id);
        Plan plan = PlanConvert.convertToPlan(planEntity);
        return plan;
    }

    @Override
    public PlanSet getPlanSet(Long planId) {
        Plan plan = this.findPlanById(planId);
        PlanSet planSetInfo = plan.getPlanSetInfo(planSetRepository);
        return planSetInfo;
    }
}
